package com.viewmode1;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.SavedStateViewModelFactory;
import androidx.lifecycle.ViewModelProviders;

import android.os.Bundle;

import com.viewmode1.databinding.ActivityScoreBinding;

//篮球积分器
public class ScoreActivity extends AppCompatActivity {
    ScoreViewModel viewModel;
    ActivityScoreBinding binding;
    static final String TEAM_A = "teamA";
    static final String TEAM_B = "teamb";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_score);
        viewModel = ViewModelProviders.of(this).get(ScoreViewModel.class);

//        //返回后台数据被杀死后的数据恢复方式1
//        if (savedInstanceState != null) {
//            viewModel.getTeamA().setValue(savedInstanceState.getInt(TEAM_A));
//            viewModel.getTeamB().setValue(savedInstanceState.getInt(TEAM_B));
//        }
//        //返回后台数据被杀死后的数据恢复方式1

        binding.setData(viewModel);
        binding.setLifecycleOwner(this);
    }

//    //返回后台数据被杀死后的数据恢复方式1
//    @Override
//    protected void onSaveInstanceState(@NonNull Bundle outState) {
//        super.onSaveInstanceState(outState);
//        outState.putInt(TEAM_A, viewModel.getTeamA().getValue());
//        outState.putInt(TEAM_B, viewModel.getTeamB().getValue());
//    }
//    //返回后台数据被杀死后的数据恢复方式1
}
